package com.axend.aerosense.dev.adapter;

import com.axend.aerosense.common.adapter.BaseBindingAdapter;
import com.axend.aerosense.common.bean.RadarType;
import com.axend.aerosense.dev.R;
import com.axend.aerosense.dev.databinding.DevLayoutChooseDeviceItemBinding;
import com.axend.aerosense.base.bean.ChooseDeviceBean;

public class DevChooseDeviceAdapter extends BaseBindingAdapter<ChooseDeviceBean.DeviceInfo, DevLayoutChooseDeviceItemBinding> {

    private OnItemClickListener onItemClickListener;

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.dev_layout_choose_device_item;
    }

    @Override
    protected void onBindItem(DevLayoutChooseDeviceItemBinding binding, ChooseDeviceBean.DeviceInfo item, int position) {
        if (null == item) {
            return;
        }

        RadarType radarType = RadarType.getType(item.getRadarType());
        if (null == radarType) {
            return;
        }

        binding.devName.setText(radarType.getName());
//        Glide.with(binding.devImage.getContext())
//                .load(item.getRadarTypeUrl())
//                .into(binding.devImage);
        RadarType.setRadarImageRes(getContext(), binding.devImage, radarType);

        binding.devItemConstraintLayout.setOnClickListener(v -> {
            if (onItemClickListener != null)
                onItemClickListener.onClick(radarType);
        });
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onClick(RadarType deviceType);
    }
}
